package com.capgemini.simpleappblanche.domain.customer;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.capgemini.simpleappblanche.domain.Agency;
import com.capgemini.simpleappblanche.domain.constant.CustomerConstant;
import com.capgemini.simpleappblanche.dto.enumeration.Title;

@Getter
@Setter
@ToString(of={"id"})
@EqualsAndHashCode(of={"id"})
@Entity
@Table(name = "CUSTOMER")
@SequenceGenerator(name = "customer_id_generator", sequenceName = "SEQUENCE_CUSTOMER", allocationSize = 1)
public class Customer {
	
	// Technical id
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "customer_id_generator")
	@Column(name = "CUSTOMER_ID")
	private Long id;
	
	@Enumerated(EnumType.STRING)
	@Column( name="TITLE")
	private Title title;
	
	@Column( name = "NAME" ,length = CustomerConstant.LENGTH_NAME, nullable = false)
	private String name;
	
	@Column( name = "FIRSTNAME",length = CustomerConstant.LENGTH_FIRSTNAME)
	private String firstname;
	
//	@OneToMany(mappedBy="customer",fetch=FetchType.LAZY)
//	@OrderBy("number")
//	private List<Email> emails;
	
	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "customers", cascade = CascadeType.ALL)
    private List<Agency> agencies;
}
